class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://github.com/offensive-security/exploitdb.git",
      tag:      "2022-02-19",
      revision: "f2d7e05ad0527fe99dfde6c0b08351cf79ba2042"
  version "2022-02-19"
  license "GPL-2.0-or-later"
  head "https://github.com/offensive-security/exploitdb.git", branch: "master"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_monterey: "660417734c5b5f1a0be2e3583aec436f8c5609d14f143efde99c00745303fed5"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "b62d96a7940fd9ba6c5d5bf3d6d4c173e77f30725d3dd2c8fb665f6cdd3cd4b4"
    sha256 cellar: :any_skip_relocation, monterey:       "47bc1c45501299f5aa553ecce4f4ec268f8334580aa580e7558336e516ef4834"
    sha256 cellar: :any_skip_relocation, big_sur:        "7f8b8dc328b343a36cc28634dcf259693cc03bd1f59b765484bc2c9cd19ffad7"
    sha256 cellar: :any_skip_relocation, catalina:       "79fdcf0abadfb602f7a6b000ae2d1eeaddf0c2c79b909cfadbedd441d5f9a1bf"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "fec47ae50b461fc35bfe641aeb528bab9192bdce55fc7dc3d8a0643607e0cf70"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
